package com.thinkfit.jy.presenter;

import com.common.lib.bean.BannerBean;
import com.common.lib.bean.ProceduralTrainBean;
import com.common.lib.manager.DataManager;
import com.common.lib.mvp.BasePresenter;
import com.common.lib.network.HttpListener;
import com.common.lib.network.HttpMethods;
import com.common.lib.network.HttpObserver;
import com.thinkfit.jy.activity.ProceduralTrainingActivity;
import com.thinkfit.jy.contract.MainContract;
import com.thinkfit.jy.utils.DeviceTypeUtils;

import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.util.ArrayList;

public class MainPresenter extends BasePresenter<MainContract.View> implements MainContract.Presenter {

    public MainPresenter(@NotNull MainContract.View rootView) {
        super(rootView);
    }

    @Override
    public void getAdvert() {
        HttpMethods.Companion.getInstance().getAdvert(14,
                new HttpObserver(false, getRootView(), new HttpListener<ArrayList<BannerBean>>() {
                    @Override
                    public void onSuccess(@Nullable ArrayList<BannerBean> list) {
                        if (getRootView() == null) {
                            return;
                        }
                        DataManager.Companion.getInstance().saveBannerList(list);
                    }

                    @Override
                    public void dataError(@Nullable int code, @Nullable String msg) {
                    }

                    @Override
                    public void connectError(@Nullable Throwable e) {
                    }
                }, getCompositeDisposable()));
    }

    @Override
    public void getVideoList(int type) {
        HttpMethods.Companion.getInstance().getVideoList(DeviceTypeUtils.getDeviceType(),type,0,0,100
                ,new HttpObserver(true, getRootView(), new HttpListener<ProceduralTrainBean>() {
                    @Override
                    public void onSuccess(@Nullable ProceduralTrainBean bean) {
                        if (getRootView() == null) {
                            return;
                        }
                        ((ProceduralTrainingActivity)getRootView()).getVideoListSuccess(bean);
//                        DataManager.Companion.getInstance().saveBannerList(list);
                    }

                    @Override
                    public void dataError(@Nullable int code, @Nullable String msg) {
                    }

                    @Override
                    public void connectError(@Nullable Throwable e) {
                    }
                }, getCompositeDisposable()));
    }


}
